package parser

import (
	"demo02/crawler/engine"
	"regexp"
)

const cityRe = `<a href="(http://album.zhenai.com/u/\d+)"[^>]+>([^<]+)</a>`

func ParseCity(content []byte) engine.ParseRequest {
	re := regexp.MustCompile(cityRe)

	matches := re.FindAllSubmatch(content, -1)
	result := engine.ParseRequest{}
	for _, m := range matches {
		result.Items = append(result.Items, string(m[2]))
		name := string(m[2])
		result.Requests = append(result.Requests, engine.Request{
			Url:  string(m[1]),
			Code: "gbk",
			ParserFunc: func(content []byte) engine.ParseRequest {
				return ParseProfile(content, name)
			},
		})
	}
	return result
}
